#include <Math/Math.hpp>
#include <Math/Random.hpp>
#include <UnitTest++.h>
using namespace zzz;
SUITE(MATHTEST)
{
  TEST(IsNaNTest)
  {
    double c=0;
    double a=1.0/c;
    float b=1.0f/c;
    CHECK(IsInf(a));
    CHECK(IsInf(b));
    CHECK(!IsInf(c));
    CHECK(IsNaN(a-b));

    CHECK(IsBad(a));
    CHECK(IsBad(b-a));
  }

  TEST(StaticIntPow)
  {
    const int r=StaticPow<2,3>::RESULT;
    CHECK_EQUAL(8,r);
  }

  TEST(MagicSqrt)
  {
    RandomReal<float> r(0,999999);
    for (int i=0; i<10; i++)
    {
      float x=r.Rand();
      float root0=Sqrt(x);
      float root1=MagicSqrt(x);
      CHECK_CLOSE(root0,root1,x/1000000.0f);
      CHECK_CLOSE(1.0f/root0,MagicInvSqrt(x),x/1000000.0f);
      CHECK_CLOSE(1.0f/root0,MagicInvSqrt2(x),x/1000000.0f);
    }
  }
}